#include <pthread.h>
#include <stdint.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdlib.h>

#define NIT_SHORT_NAMES
#include <nit/socket.h>

#include "tr.h"

int
blu_trad_init(Blu_trad *tr, int32_t max)
{
	tr->msg = 0;
	tr->max = max;

	return !!(tr->buf = malloc(max));
}

int
blu_trad_release(Blu_trad *tr)
{
	free(tr->buf);
}

enum nit_join_status
blu_tr(Nit_joint *in, Blu_trad *tr)
{
	return joint_read(in, &tr->buf, &tr->max, &tr->msg, 0);
}

int
blu_tr_rate_change(Nit_joint *in, double sps)
{
	if (!joint_send(in, &sps, sizeof(sps)))
		return 0;

	return 1;
}
